package com.practice.java.practice2Protobuf;

import com.google.protobuf.InvalidProtocolBufferException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * https://protobuf.dev/getting-started/javatutorial/
 */
public class TestProtobuf {
    public static void main(String[] args) {
        Logger logger = LoggerFactory.getLogger(TestProtobuf.class);
        Person john = Person.newBuilder()
                        .setId(1234)
                        .setName("John Doe")
                        .setEmail("jdoe@example.com")
                        .addPhones(
                                Person.PhoneNumber.newBuilder()
                                        .setNumber("555-4321")
                                        .setType(Person.PhoneType.PHONE_TYPE_HOME)
                                        .build())
                .build();
        byte[] array = john.toByteArray();
        try {
            Person johnCopy = Person.parseFrom(array);
            logger.info("JohnCopy:{}",johnCopy);
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
    }
}
